home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ole / ole2.frm < prev   
Text File  |  1995-05-08  |  7KB  |  295 lines

  1. VERSION 2.00
  2. Begin Form frm_main 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "OLE Destination Example"
  5.    ClientHeight    =   3180
  6.    ClientLeft      =   2025
  7.    ClientTop       =   2295
  8.    ClientWidth     =   3885
  9.    Height          =   3870
  10.    Left            =   1965
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   80.379
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   101.39
  16.    Top             =   1665
  17.    Width           =   4005
  18.    Begin OLE ole_Destination 
  19.       fFFHk           =   -1  'True
  20.       Height          =   3135
  21.       HostName        =   "OLE Demo"
  22.       Left            =   0
  23.       TabIndex        =   0
  24.       Top             =   0
  25.       Verb            =   -1
  26.       Width           =   3855
  27.    End
  28.    Begin Menu mnuFile 
  29.       Caption         =   "&File"
  30.       Begin Menu mnuExit 
  31.          Caption         =   "E&xit"
  32.       End
  33.    End
  34.    Begin Menu mnuedit 
  35.       Caption         =   "&Edit"
  36.       Begin Menu mnuName 
  37.          Caption         =   "None"
  38.          Enabled         =   0   'False
  39.          Begin Menu mnuVerbs 
  40.             Caption         =   "Verbs"
  41.             Index           =   0
  42.          End
  43.       End
  44.       Begin Menu mpaste 
  45.          Caption         =   "&Paste"
  46.       End
  47.       Begin Menu mplink 
  48.          Caption         =   "Paste &Link"
  49.       End
  50.       Begin Menu mnuPasteSpecial 
  51.          Caption         =   "Paste &Special"
  52.       End
  53.       Begin Menu mnuInsert 
  54.          Caption         =   "&Insert Object"
  55.       End
  56.       Begin Menu sep 
  57.          Caption         =   "-"
  58.       End
  59.       Begin Menu mdel 
  60.          Caption         =   "&Delete Object"
  61.       End
  62.       Begin Menu mnuSep2 
  63.          Caption         =   "-"
  64.       End
  65.       Begin Menu mnuUpdate 
  66.          Caption         =   "&Update"
  67.       End
  68.    End
  69. End
  70. Option Explicit
  71.  
  72. Dim aPath As String
  73.  
  74. Sub Form_Load ()
  75.     Dim FileNum ' Declare variable.
  76. '
  77. '   Get startup Path of OLE2 Application
  78. '
  79.     aPath = app.Path
  80.     If Right$(aPath, 1) <> "\" Then
  81.     aPath = aPath + "\"
  82.     End If
  83. '
  84. '   Setup file for OLE
  85. '   If present read and restore OLE control
  86. '
  87.     FileNum = FreeFile  ' Get a valid file number.
  88.     On Error GoTo oleErr
  89.     Open aPath & "oleTst.OLE" For Binary As FileNum   ' Open file to be saved.
  90.     ole_Destination.FileNumber = FileNum ' Set the OLEClient filenumber.
  91.     ole_Destination.Action = 12  ' read the file.
  92.     Close #FileNum  ' Close the file.
  93.     mnuName.Caption = ole_Destination.Class
  94.  
  95. continue:
  96.     If windowstate = 1 Then Exit Sub
  97.     Me.ScaleMode = 1
  98.     Me.Width = (ole_Destination.Width + 300)
  99.     Me.Height = (ole_Destination.Height + 800)
  100.     Me.ScaleMode = 6
  101.     Exit Sub
  102.  
  103. oleErr:
  104. '
  105. '   OLETST.OLE file not found OK OLE Object set to NULL
  106. '
  107.     Close #FileNum  ' Close the file.
  108.     mnuName.Caption = "No Object"
  109.     Resume continue
  110. End Sub
  111.  
  112. Sub Form_Unload (Cancel As Integer)
  113.     Dim FileNum ' Declare variable.
  114. '
  115. '   If object is in OLE control save it to file!
  116. '
  117.     If ole_Destination.OLEType <> 3 Then
  118.     FileNum = FreeFile  ' Get a valid file number.
  119.     Open aPath & "oleTst.OLE" For Binary As FileNum   ' Open file to be saved.
  120.     ole_Destination.FileNumber = FileNum ' Set the OLEClient filenumber.
  121.     ole_Destination.Action = 11  ' Save the file.
  122.     Close #FileNum  ' Close the file.
  123.     Else
  124.     Kill aPath & "oletst.ole"   'Erase old OLE File
  125.     End If
  126. '
  127. '   Stop execution of Application
  128. '
  129.     End
  130. End Sub
  131.  
  132. Sub mdel_Click ()
  133. '
  134. '   Delete the OLE object in the OLE Control
  135. '
  136.     If ole_Destination.OLEType = 3 Then
  137.     Beep
  138.     Else
  139.     ole_Destination.Action = 10      'Delete Object
  140.     '
  141.     '   Restore original size
  142.     '
  143.     If windowstate = 1 Then Exit Sub
  144.     Me.ScaleMode = 1
  145.     Me.Width = (ole_Destination.Width + 300)
  146.     Me.Height = (ole_Destination.Height + 800)
  147.     Me.ScaleMode = 6
  148.     End If
  149.     mnuName.Caption = "No Object"
  150. End Sub
  151.  
  152. Sub mnuedit_Click ()
  153.     Dim Verb As Integer
  154. '
  155. '   Check clipboard and greyout Edit commands
  156. '   as needed
  157. '
  158.     If ole_Destination.PasteOK Then
  159.     mPaste.Enabled = True
  160.     mpLink.Enabled = True
  161.     mnuPasteSpecial.Enabled = True
  162.     Else
  163.     mPaste.Enabled = False
  164.     mpLink.Enabled = False
  165.     mnuPasteSpecial.Enabled = False
  166.     End If
  167.     If ole_Destination.OLEType = 3 Then  'None
  168.     mDel = False
  169.     mnuUpdate.Enabled = False
  170.     mnuName.Enabled = False
  171.     mnuInsert.Enabled = True
  172.     Else
  173.     mDel = True
  174.     mnuUpdate.Enabled = True
  175.     mnuName.Enabled = True
  176.     mnuInsert.Enabled = False
  177.     End If
  178. '
  179. '   OLE Object Class name
  180. '   and cascade menu of verbs
  181. '
  182. '   Set Form properties now that it contains an object.
  183. '
  184.     On Error Resume Next
  185.     For Verb = 1 To ole_Destination.ObjectVerbsCount - 1
  186.     Load mnuVerbs(Verb - 1)
  187.     If Err = 360 Then       'Object already loaded.
  188.     Unload mnuVerbs(Verb - 1)
  189.     Load mnuVerbs(Verb - 1)
  190.     Err = 0
  191.     End If
  192.     mnuVerbs(Verb - 1).Caption = ole_Destination.ObjectVerbs(Verb - 1)
  193.     Next Verb
  194. End Sub
  195.  
  196. Sub mnuExit_Click ()
  197.     Unload Me
  198. End Sub
  199.  
  200. Sub mnuInsert_Click ()
  201. '
  202. '   Use Insert Object Dialog Box to build new OLE
  203. '   Object.  User chooses OLE Application to
  204. '   create this new object from OLE Registration
  205. '   database (REG.DAT)
  206. '
  207.     On Error GoTo insertErr
  208.     If ole_Destination.OLEType <> 3 Then
  209.     Beep
  210.     Exit Sub
  211.     End If
  212.     ole_Destination.Action = 14      'Insert Object Dialog Box
  213.     ole_Destination.Action = 7       'OLE Activate
  214.     mnuName.Caption = ole_Destination.Class
  215.     Exit Sub
  216.  
  217. insertErr:
  218.     MsgBox "OLE ERROR - Inserting Object"
  219.     Resume 0
  220. End Sub
  221.  
  222. Sub mnuPasteSpecial_Click ()
  223. '
  224. '   Show Paste Special Dialog Box
  225. '   Allows user to choose Embed or Link type
  226. '
  227.     If ole_Destination.PasteOK Then
  228.     ole_Destination.Action = 15  'Paste Special
  229.     Else
  230.     Beep
  231.     End If
  232.     mnuName.Caption = ole_Destination.Class
  233. End Sub
  234.  
  235. Sub mnuUpdate_Click ()
  236. '
  237. '   Update Object by calling OLE Application
  238. '
  239.     ole_Destination.Action = 6   'Update Object
  240.     mnuName.Caption = ole_Destination.Class
  241. End Sub
  242.  
  243. Sub mnuVerbs_Click (Index As Integer)
  244. '
  245. '   Execute a verb to OLE Application
  246. '
  247.     ole_Destination.Verb = Index
  248.     If UCase(mnuVerbs(Index).Caption) = "&EDIT" Then ole_Destination.Verb = -1    'In-Place-Edit
  249.     ole_Destination.Action = 7   'Activate
  250. End Sub
  251.  
  252. Sub mpaste_Click ()
  253. '
  254. '   Paste from Clipboard (Embedded Type)
  255. '
  256.     ole_Destination.OLEType = 1  ' Embedded
  257.     If ole_Destination.PasteOK Then
  258.     ole_Destination.Action = 5   'Paste
  259.     Else
  260.     Beep
  261.     End If
  262.     mnuName.Caption = ole_Destination.Class
  263. End Sub
  264.  
  265. Sub mplink_Click ()
  266. '
  267. '   Paste from clipboard (Link Type)
  268. '
  269.     ole_Destination.OLEType = 0  ' Linked
  270.  
  271.     If ole_Destination.PasteOK Then
  272.     ole_Destination.Action = 5  'Paste
  273.     Else
  274.     Beep
  275.     End If
  276.     mnuName.Caption = ole_Destination.Class
  277. End Sub
  278.  
  279. Sub ole_Destination_Updated (Code As Integer)
  280. '
  281. '   Gets control when object was changed by
  282. '       OLE Application
  283. '
  284.     Dim rc As Integer
  285.     If ole_Destination.OLEType = 3 Then
  286.     Exit Sub
  287.     End If
  288.     If windowstate = 1 Then Exit Sub
  289.     Me.ScaleMode = 1
  290.     Me.Width = (ole_Destination.Width + 300)
  291.     Me.Height = (ole_Destination.Height + 800)
  292.     Me.ScaleMode = 6
  293. End Sub
  294.  
  295.